package com.clickpaas.timelineofUN.common.Interceptor;

import com.bizcloud.ipaas.t7aef1c33e4a445f2833f9d631cb90c38.d20210202091529.auth.extension.AuthConfig;
import com.clickpaas.timelineofUN.config.AutoLoadConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @company <上海爱湃斯科技有限公司>
 * @email <zhihui.peng@clickpaas.com>
 * @author huiye
 * @decription: 拦截器验证用户登陆token
 * @date 2020/12/27 1:22 下午
 */
@Slf4j
public class InitVerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        try {
            String token = request.getHeader("tg-token");
            init(AutoLoadConfig.ACCESSKEYID,AutoLoadConfig.ACCESSKEYSECRET,token);
            return true;
        }catch (Exception e){
            return false;
        }

    }

    public void init( String accesskeyId, String accesskeySecret, String token) {
        AuthConfig authConfig = new AuthConfig(accesskeyId, accesskeySecret, token);
        authConfig.initAuth();
    }

}
